package redisenum

import (
	"errors"
	"time"

	"yunj/pkg/yunj/util"
)

// 定义redis key常量
const (
	// 测试
	KEY_YUNJ_TEST string = "yunj.test:"

	// 后台成员id，根据token
	KEY_ADMIN_MEMBER_ID_BY_TOKEN string = "admin.member.id.by.token:"
)

func (rk *Key) AllConstAttrs() map[string]map[string]any {
	return map[string]map[string]any{
		KEY_YUNJ_TEST: {
			"desc": "测试",
			"keySuffix": func(rk KeyInterface) (suffix string, err error) {
				if args, ok := rk.GetArgs().(map[string]any); ok {
					if id, exists := args["id"]; exists {
						suffix, err = util.ToString(id)
						return
					}
				}
				err = errors.New("args参数异常")
				return
			},
			"value": func(rk KeyInterface) (any, error) {
				return time.Now().Format("2006-01-02 15:04:05"), nil
			},
		},
		KEY_ADMIN_MEMBER_ID_BY_TOKEN: {
			"desc": "后台成员id，根据token",
			"keySuffix": func(rk KeyInterface) (suffix string, err error) {
				if token, ok := rk.GetArgs().(string); ok {
					suffix = token
					return
				}
				err = errors.New("args参数异常")
				return
			},
			"value": func(rk KeyInterface) (any, error) {
				return time.Now().Format("2006-01-02 15:04:05"), nil
			},
		},
	}
}
